#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int t;
int n,m;int d,fv,a,l,v;
int w[N];
struct node{
    int cl,cr;
}e[N];
bool cmp(node x,node y){
    if(x.cl==y.cl)return x.cr<y.cr;
    return x.cl<y.cl;
}
bool cmp2(node x,node y){
    if(x.cr-x.cl==y.cr-y.cl)return x.cl<y.cl;
    return (x.cr-x.cl)<(y.cr-y.cl);
}
int dp[N],nans;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        nans=0;
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>d>>fv>>a;
            if(fv>v){
                e[i].cl=d;
                if(a>=0)e[i].cr=l;
                else {
                    int nr=d+((v*v-fv*fv)/(2*a));
                    int vr=(nr-d)*(2*a)+fv*fv;
                    if(vr==v*v){nr--;}
                    e[i].cr=min(l,nr);
                }
            }else{
                if(a<=0){
                    e[i].cl=e[i].cr=N-3;
                }else{
                    int nr=d+((v*v-fv*fv)/(2*a));
                    int vr=(nr-d)*(2*a)+fv*fv;
                    if(vr==v*v){nr++;}
                    if(nr<=l){
                        e[i].cl=nr;e[i].cr=l;
                    }else{
                        e[i].cl=e[i].cr=N-3;
                    }
                }
            }
        }
        sort(e+1,e+n+1,cmp);
        for(int i=1;i<=m;i++){
            cin>>w[i];
        }
        for(int i=1;i<=n;i++){
            if(e[i].cl>l){n=i-1;break;}
            int ll=1,rr=m;
            while(ll<rr){
                int mid=ll+rr>>1;
                if(e[i].cl<=w[mid])rr=mid;
                else ll=mid+1;
            }
            if(e[i].cl>w[ll])ll=N;
            int rll=1,rrr=m;
            while(rll<rrr){
                int mid=(rll+rrr+1)>>1;
                if(e[i].cr>=w[mid])rll=mid;
                else rrr=mid-1;
            }
            if(e[i].cr<w[rll])rll=0;
            if(ll<=rll){
                e[i].cl=ll;e[i].cr=rll;nans++;
            }else{
                e[i].cl=e[i].cr=N-3;
            }
        }
        cout<<nans<<' ';
        sort(e+1,e+n+1,cmp);
        for(int i=1;i<=n;i++){
            if(e[i].cl>l){n=i-1;break;}
        }
        sort(e+1,e+n+1,cmp2);
        for(int i=1;i<=n;i++){
            for(int j=1;j<i;j++){
                if(e[i].cl<=e[j].cl&&e[j].cr<=e[i].cr){
                    e[i].cl=e[i].cr=N-3;break;
                }
            }
        }
        sort(e+1,e+n+1,cmp);
        int nnr=0;
        for(int i=1;i<=n;i++){
            if(e[i].cl>l){n=i-1;break;}
        }
        int nans2=0;
        int ml=e[n].cr+1;
        for(int i=n;i>=1;i--){
            if(e[i].cr<ml){
                ml=e[i].cl;nans2++;
            }
        }
        cout<<m-nans2<<endl;
    }
    return 0;
}